V12. Odds & Ends

INIT Problems
  In 1990 we wrote:  "The interaction between programs, INITs, new System Software, and new versions of the Mac seems to be getting increasingly unstable.  When all else fails, try removing an INIT!"  This advice continues to be true, especially with the new Macintosh Quadra.

Clobbered Variables
  A common problem encounterd by programmers new to FaceWare occurs when they forget that most fRec variables are scratch variables that can be changed by any call to the FaceIt dispatching procedure or to the Control Manager (since the Control Manager calls ViewIt via CDEF 1200).  The scratch variables include all those prefixed by letters "u", "w", or "c".  The rule of thumb to follow is that if you will be using such an fRec variable in more than one FaceIt or Control Manager call, then save a copy of its contents in a local variable and use the copy.  (Exceptions:  Most UtilIt commands and utility-type modules preserve the "w" and "c" variables.)
  Suppose, for example, that a control handle is needed for use in a single call to SizeControl.  In this case you can get away with using cControl:
 FaceIt(nil,GetCtl,1030,0,1,5);
 SizeControl(fRec.cControl,100,100);
But if the control handle is also used in a subsequent call, then a copy of cControl should be used:
 FaceIt(nil,GetCtl,1030,0,1,5);
 theControl := fRec.cControl;
 SizeControl(theControl,100,100);
 FaceIt(nil,AddCtl,1004,0,ord(theControl),0);
since both the Control Manager and FaceIt calls can result in clobbering the current values in fRec.
  The same precaution should be taken with commonly used variables such as uString, uMenuID, uMenuItem, wvHit, and wcHit, although these are most often used as simple case selectors in case blocks in a way that does not require their contents to be saved.

Program Drawing
  Any drawing that a main program does with QuickDraw always occurs within the current port.  If using FaceIt, the current port will almost always be the active window since FaceIt sets the port to the active window whenever DoLoop is called.  If you need to draw into a window that is not the active window, then call SetPort to first reset the current port to that window.  This should also be done before using calls such as GlobalToLocal and LocalToGlobal since these are a function of the current port.  (If drawing from within a control driver or override procedure, then you don't have to worry about this since the current port is always reset to the port containing the control before a driver is called.)

The Help Key
  The "help" key (ASCII 5) on Mac keyboards is converted by ViewIt to the command key combination "âŒ˜/".  To use a different command key for "help", change the first string in STR# 1203 from "/" to some other character.

Spurious Events
  The FaceIt dispatching procedure contains a FlushEvents call that removes all key and mouse events from the event queue the first time FaceIt is called.  Another use of this toolbox call is to clear any spurious key and mouse events that occur during execution of a time-consuming routine within the main program.  Simply insert a FlushEvents call after such a routine to prevent any accumulated mouse or key events in the event queue from being processed "all at once" when control is returned to FaceIt.